package demo5;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: xiaotutu
 * Date: 2024-03-08
 * Time: 17:05
 */

//实现一个简单的控制台版用户登陆程序, 程序启动提示用户输入用户名密码.
// 如果用户名密码出错, 使用自定义异常的方式来处理

public class logIn {
    private String passWord = "123456";

    public  void loginInfo(String passWord) throws PassWord {
        if(!this.passWord.equals(passWord)) {
            throw new PassWord("密码异常!");
        }
        System.out.println("登陆成功!");
    }

    public static void main(String[] args) {
        logIn login = new logIn();
        System.out.println("请输入密码: ");
        Scanner scanner = new Scanner(System.in);
        String passWord = scanner.nextLine();
        try {
            login.loginInfo(passWord);
        } catch (PassWord e) {
            e.printStackTrace();
        }
    }
}


/*public class logIn {
    private String userName = "admin";
    private String passWord = "123456";

    public  void loginInfo(String userName, String passWord) throws UserName, PassWord {
       if(!this.userName.equals(userName)) {
           throw new UserName("用户名异常!");
       }
        if(!this.passWord.equals(passWord)) {
            throw new PassWord("密码异常!");
        }
    }

    public static void main(String[] args) {
        logIn login = new logIn();
        try {
            login.loginInfo("admin","1553");
        } catch (UserName e) {
            e.printStackTrace();
        } catch (PassWord e) {
            e.printStackTrace();
        }
    }
}*/
